package com.example.airport.data;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.example.airport.R;
import com.example.airport.utils.DictUtil;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class BookAdapter extends RecyclerView.Adapter<BookAdapter.ViewHolder> {
    private FixedSizeLinkedList<Book> mBookList;

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.book_name)
        TextView bookName;

        @BindView(R.id.book_text)
        TextView bookText;


        @BindView(R.id.imageView1)
        ImageView imageView1;

        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }


    @Override
    public int getItemViewType(int position) {
        return mBookList.get(position).getType();
    }


    public BookAdapter() {

    }

    public void bindData(FixedSizeLinkedList<Book> bookList) {
        mBookList = bookList;
    }

    @Override
    public BookAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view;
         if (viewType == 0) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout_1, parent, false);
        } else {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_layout_2, parent, false);
        }

        RecyclerView.ViewHolder holder = new ViewHolder(view);
        return (ViewHolder) holder;
    }


    @Override
    public void onBindViewHolder(BookAdapter.ViewHolder holder, int position) {
        Book book = mBookList.get(position);
        String _reporter=book.getName();
        holder.bookName.setText(DictUtil.getValue(_reporter)==null?_reporter:DictUtil.getValue(_reporter));
        holder.bookText.setText(book.getText());

//        if(book.getType()==1)
//        {
            switch (book.getName())
            {
                case "C001":
                    holder.imageView1.setImageResource(R.mipmap.c001);
                    break;
                case "C002":
                    holder.imageView1.setImageResource(R.mipmap.c002);
                    break;
                case "C003":
                    holder.imageView1.setImageResource(R.mipmap.c003);
                    break;
                case "C004":
                    holder.imageView1.setImageResource(R.mipmap.c004);
                    break;
                case "C005":
                    holder.imageView1.setImageResource(R.mipmap.c005);
                    break;

            }

//        }

    }


    @Override
    public int getItemCount() {
        return mBookList.size();
    }
}